package 刷题10月.每日一题0930;
// https://leetcode-cn.com/problems/arranging-coins/
public class 每日441排列硬币1010 {
    class Solution {
        public int arrangeCoins(int n) {
            int sum=0;
            for(int i=1;i<=n;i++){
                if(n==Integer.MAX_VALUE){
                    return 65535;
                }
                sum+=i;
                if(sum>n)
                    return i-1;
                else if(sum==n){
                    return i;
                }
            }
            return 1;
        }
    }
}
/*
//二分
class Solution {
    public int arrangeCoins(int n) {
        long l = 1, r = n;
        while (l < r) {
            long mid = l + r + 1 >> 1;
            if (mid * (mid + 1) / 2 <= n) l = mid;
            else r = mid - 1;
        }
        return (int)r;
    }
}
//数学等差数列
class Solution {
    public int arrangeCoins(int n) {
        return (int)((Math.sqrt(1 + 8.0 * n) - 1) / 2);
    }
}

作者：AC_OIer
链接：https://leetcode-cn.com/problems/arranging-coins/solution/gong-shui-san-xie-yi-ti-shuang-jie-shu-x-sv9o/
来源：力扣（LeetCode）
著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。

 */
